﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Comod_GiftsMange : ATPages
{
    ZSql zs = new ZSql();
    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            initgvData();
            lblPath.Text = f.getModuleidAdd(Request["moduid"]);
        }
    }
    protected void btnSelec_Click(object sender, EventArgs e)
    {
        string sql = "select stockId,b.ComoditiesName,procnum,procMoney,username,Content,IsOut from CS_Stock a join ComoditiesName b on a.ComoditiesName=b.ComoditiesNameId where typeStock='赠品' ";
        if (!string.IsNullOrEmpty(txtselecName.Text))
        {
            sql += " and b.ComoditiesName='" + txtselecName.Text + "'";
        }
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;
    }
    private void initgvData()
    {
        string sql = "select stockId,b.ComoditiesName,TotalNum,procMoney,username,Content,IsOut from CS_Stock a join ComoditiesName b on a.ComoditiesName=b.ComoditiesNameId where typeStock='赠品'";
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {

        if (this.GvData.Rows.Count > 0)
        {
            for (int i = 0; i < GvData.Rows.Count; i++)
            {
                CheckBox ck = GvData.Rows[i].Cells[6].FindControl("ckFlag") as CheckBox;
                if (ck.Checked)
                {

                    zs.Open("update  CS_Stock set IsOut=1 where stockId=" + this.GvData.Rows[i].Cells[0].Text);

                }
                else
                {
                    zs.Open("update  CS_Stock set IsOut=0 where stockId=" + this.GvData.Rows[i].Cells[0].Text);
                }


            }
        }
        ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('设置成功');", true);
    }
    protected void GvDataBand_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string AuditState = DataBinder.Eval(e.Row.DataItem, "IsOut").ToString();
            CheckBox ck = e.Row.Cells[6].FindControl("ckFlag") as CheckBox;
            if (AuditState == "1")
            {
                ck.Checked = true;

            }

        }
    }
    protected void btnPrint_Click(object sender, EventArgs e)
    {
        string id="1";
        if (CheckBox1.Checked)
	    {
                id="0";
	    }
       
        ClientScript.RegisterStartupScript(typeof(Page), "aa", "PrintData('"+id+"')", true);
    }
}
